<?php
/**
 * User: lsx
 * Date: 2017/4/21
 * Time: 14:31
 * Progress:0%
 */

namespace logic\admin\wechat;



use model\WechatSetting;

class LWechatSetting
{
    public function index(){
        $model=new WechatSetting();
        $row=$model->where(['name'=>'wechat_mp_config'])->find();
        if($row){
            $data=$row->getData()['value'];
        }else{
            $data=false;
        }
        return $data;
    }

    public function add_data($param){
        $model=new WechatSetting();
        $item=$model->where(['name'=>'wechat_mp_config'])->find();
        if($item){
            $res=$model->where(['name'=>'wechat_mp_config'])->setField('value',json_encode($param));
        }else{
            $data=array(
                'name'=>'wechat_mp_config',
                'value'=>json_encode($param),
                'category'=>2,
                'encode'=>1,
                'title'=>'微信接口配置'
            );
            $res=$model->save($data);
        }

        if($res){
            return array(
                'success'=>true,
                'message'=>'保存成功'
            );
        }else{
            return array(
                'success'=>false,
                'message'=>'保存失败'
            );
        }
    }

}